package com.lujieni.springbootwebsocket.config;

import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {



    /**
     *  加了序列化和函数回调的RabbitTemplate
     *  加了@ConditionalOnSingleCandidate这个注解会导致自己定义的配置类无法注入 no reason
     *  @ConditionalOnSingleCandidate(ConnectionFactory.class)
     */
    @Bean
    public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
        RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
        /* 使用json序列化方式替换jdk序列化 */
        rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
        return rabbitTemplate;
    }
}
